// 生产环境的webpack配置文件
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = {
  mode: "production",
  entry: path.resolve(process.cwd(), "./src/index.js"), // 入口文件
  output: {
    path: path.resolve(process.cwd(), "./dist"),
    filename: "[name].js",
    publicPath: "/"  // 解决二级路由加载编译之后的main.js路径问题 
  },
  resolve: {
    alias: {
      // @ 符号  等同于 path.resolve(process.cwd(), "src/views")
      "@": path.resolve(process.cwd(), "src/views")
    }
  },
  module: {
    rules: [{
      test: /\.html$/i,
      loader: "html-loader",
    },
    {
      test: /\.ejs$/,
      loader: 'ejs-loader',
      options: {
        variable: 'data', // 可以在模块当中使用data进行数据处理
      }
    }]
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: "admin",
      filename: "index.html",
      template: "./public/index.html"
    }),
    new CopyWebpackPlugin({
      patterns: [{
        from: "public",
        to: "./",
        globOptions: {
          ignore: ["**/index.html"] // 排除index.html
        }
      },
      {
        from: "./src/static",
        to: "./"
      }]
    })
  ]
}